<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1.0/dist/css/adminlte.min.css" integrity="sha256-FQ+k0mIFfWXVTaW1arh3qKx8IXX5Bm5f6QG+0pkUjaE=" crossorigin>
		<link rel="preload" as="font" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/webfonts/fa-solid-900.woff2" crossorigin>
		<link rel="preload" as="font" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/webfonts/fa-regular-400.woff2" crossorigin>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css" integrity="sha256-h20CPZ0QyXlBuAw7A+KluUYx/3pK+c7lYEpqLTlxjYQ=" crossorigin>
        
		<style>
			.login-bg {
            position: fixed;
            z-index: -1;
            filter: brightness(0.5);
            width: 100vw;
            height: 100vh;
            object-fit: cover;
        }
        .login-box > .card, .login-card-body {
            border-radius: 12px;
        }
        .login-logo a {
            color: var(--light);
        }
	
        </style>

		<title>登录 - Candy</title>
	</head>

	<body class="hold-transition login-page">
		<div class="login-box">
			<div class="login-logo">
			</div>

			<div class="card">
				<div class="card-body login-card-body">
					<p class="login-box-msg">登录以管理棉花糖</p>
					<div class="css-hrpb34">
						<div role="combobox" aria-haspopup="listbox" aria-owns="react-autowhatever-1" aria-expanded="false" class="mb-3">
							<div class="input-group">
								<input id="username" class="form-control" type="text" placeholder="用户名" required="" value="">
								<div class="input-group-append">
									<div class="input-group-text">
										<i class="fas fa-user"></i>
									</div>
								</div>
							</div>
							<div id="react-autowhatever-1" role="listbox" class="dropdown"></div>
						</div>
					</div>
					<div class="input-group mb-3">
						<input id="passwd" type="password" class="form-control" placeholder="密码" required="" value="">
						<div class="input-group-append">
							<div class="input-group-text">
								<i class="fas fa-lock"></i>
							</div>
						</div>
					</div>
                    <div id="alert"></div>
					<button class="btn btn-primary btn-block" onclick="login()">登录</button>
                    <a class="btn btn-primary btn-block" href="../">返回主页</a>
				</div>
			</div>
		</div>

		<img class=login-bg src="https://i.loli.net/2021/08/23/NUHRV3LEAdOftrP.jpg">

        <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
        <script>
            $.ajax({
                type: "post",
                url: "check.php",
                data: {},
                async: false,
                success: function(data) {
                    json = JSON.parse(data);
                    if(json['code'] == 1){
                    }
                    if(json['code'] == 0){
                        location.replace("../admin");
                    }
                }
            });
            function login()
            {
                $.ajax({
                    type: "post",
                    url: "login.php",
                    data: { username:$('#username').val() , passwd:$('#passwd').val() },
                    async: false,
                    success: function(data) {
                        json = JSON.parse(data);
                        if(json['code'] == 1){
                            $('#alert').html('<div class="alert alert-warning" role="alert"><i class="icon fas fa-exclamation-triangle"></i>'+json['data']['msg']+'</div>');
                        }
                        if(json['code'] == 0){
                            $('#alert').html('<div class="alert alert-success" role="alert"><i class="icon fas fa-check"></i>'+json['data']['msg']+'</div>');
                            location.replace("../admin");
                        }
                    }
                });

            }
        </script>
  </body>
</html>